package last;

class Account{
	private  int balance;
	private java.util.concurrent.locks.Lock lock = new java.util.concurrent.locks.ReentrantLock();
    private java.util.concurrent.locks.Condition condition = lock.newCondition();

	public Account(int balance) {
		super();
		this.balance = balance;
	}

	public int getBalance() {
		return balance;
	}


  /*  public  synchronized  void deposit(int money)
	{
		balance+=money;
	}
	public synchronized  void withdraw(int money)
	{
		balance-=money;
	}*/
	public void deposit(int money)
	{
		lock.lock();
		try {
			balance+=money;
			condition.signalAll();
		} finally {
			lock.unlock();
		}
		
	}
	public void withdraw(int money)
	{
		 lock.lock();
	        try {
	            while (balance < money) {
	                try {
	                    condition.await();
	                } catch (InterruptedException e) {
	                    throw new RuntimeException(e);
	                }
	            }
	            balance -= money;
	        } finally {
	            // TODO: handle finally clause
	            lock.unlock();
	        }
	    }
}

public class Main2 {

}
